package com.example.t410.controller;
import com.alibaba.fastjson.JSONObject;
import com.example.t410.VO.AnswerVO;
import com.example.t410.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("test/")
public class TestController {
    JSONObject jsonObject = new JSONObject();
    @Autowired
    private TestService testService;
    @GetMapping("/{id}")
    public JSONObject getAll(@PathVariable Long id)
    {
        jsonObject.clear();
        jsonObject.put("status","200");
        jsonObject.put("data",testService.findAll(id));
        return jsonObject;
    }

    @PostMapping("/depression/submit")
    public JSONObject submit(@RequestBody JSONObject json)
    {
        jsonObject.clear();
        String ans = json.getString("ans");
        AnswerVO ans1 = testService.calculateAns(ans);
        if (ans1 != null) {
            jsonObject.put("status", 200);
            jsonObject.put("data", ans1);
        } else {
            jsonObject.put("status", 201);
            jsonObject.put("data", null);
        }
        return jsonObject;
    }

}
